<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateQiiFlowApplyStepTable extends Migration
{
    /**
     * Schema table name to migrate
     * @var string
     */
    public $set_schema_table = 'qii_flow_apply_step';

    /**
     * Run the migrations.
     * @table qii_flow_apply_step
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable($this->set_schema_table)) return;
        Schema::create($this->set_schema_table, function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->increments('id')->comment('ID');
            $table->unsignedInteger('category_id')->default('0')->comment('流程模型ID(冗余字段,用于待我处理列表页展示)');
            $table->unsignedInteger('apply_id')->default('0')->comment('申请ID');
            $table->unsignedInteger('step_id')->default('0')->comment('步骤ID');
            $table->unsignedInteger('user_id')->default('0')->comment('流程步骤审核人ID');
            $table->unsignedSmallInteger('is_done')->default('0')->comment('是否已经处理(0未处理,1已处理)');
            $table->unsignedSmallInteger('is_agree')->default('0')->comment('是否通过(0驳回,1通过)');
            $table->unsignedInteger('modify')->default('0')->comment('审核时间');

            $table->index(["user_id"], 'user');

            $table->index(["user_id", "is_done"], 'user_done');

            $table->unique(["user_id", "apply_id", "category_id", "is_done", "step_id"], 'user_apply_category_done_step');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
     public function down()
     {
       Schema::dropIfExists($this->set_schema_table);
     }
}
